// import store from "@/public/store.js"
//  export const baseUrl  = 'https://td.lszbg.com' //线上正式域名https://h5.hwhsh.com https://td.lszbg.com
  export const baseUrl  =  'https://td.test.lszbg.cn'//测试域名 https://shengtan.hwhsh.com
const requestSettings = (opt) => {
	opt.url = baseUrl + opt.url
	return opt
}
const getSuccessInfo = async (response, data, resolve, reject) => {

	let res = response.data
	if (res.code == 200 && res.status == 1) {
		resolve(response)
	} else if (res.code === 200 && res.status === -1) {
		uni.removeStorageSync('userinfo');
		uni.removeStorageSync('token');
		uni.removeStorageSync('wechat_login_tag');

		//#ifdef APP-PLUS
		uni.navigateTo({
			url: '/subpackageB/pages/newAppLogin/newAppLogin'
		})
		//#endif

		// #ifdef MP-WEIXIN || H5
		// uni.navigateTo({
		// 	url: '/pages/login/login'
		// })
		// #endif

	} else {
		reject(response)
	}
}
const getFailInfo = (error) => {
	// 网络异常的数据判断
	uni.hideLoading()
	return error
}
const request = function(data) {
	return new Promise(function(resolve, reject) {
		uni.request(requestSettings({
			...data,
			header: {
				'Content-Type': 'application/json',
				'authorization': uni.getStorageSync('token')
			},
			success: (res) => {
				getSuccessInfo(res, data, (res) => {
					resolve(res)
				}, (err) => {
					reject(err)
				})
			},
			fail: (err) => {
				reject(getFailInfo(err))
			}
		}))
	})
}
export default request
